<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>5.天气案例_监视简写形式</title>
    <!-- 引入Vue -->
    <script type="text/javascript" src="../js/vue.js"></script>
</head>

<body>
    <!-- 准备好一个容器-->
    <div id="demo">
        <h2>今天天气很{{info}}</h2>
        <button @click="changeWeather">切换天气</button><br>
        <img :src="url" alt="">
    </div>
</body>

<script type="text/javascript">
    //阻止 vue 在启动时生成生产提示。
    Vue.config.productionTip = false
    const vm = new Vue({
        el: '#demo',
        data: {
            isHot: true,
            url: './imgs/re.jpg'
        },
        computed: {
            info() {
                return this.isHot = !this.Hot?'炎热':'凉爽'
            }
        },
        methods: {
          changeWeather(){
              this.isHot = !this.isHot
          }  
        },
        watch:{
            isHot(value){
                if(value) this.url = './imgs/re.jpg'
                else this.url ='./imgs/cool.jpg'
            }
        }
    })
</script>

</html>